
package com.loong.loong.hik.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.loong.loong.common.core.util.R;
import com.loong.loong.hik.entity.CarBarrier;
import com.loong.loong.hik.mapper.CarBarrierMapper;
import com.loong.loong.hik.property.request.car.CarDeviceControlRequestDto;
import com.loong.loong.hik.property.result.car.CarDeviceControlResultVo;
import com.loong.loong.hik.property.urls.face.HikFaceUrl;
import com.loong.loong.hik.service.CarBarrierService;
import com.loong.loong.hik.service.HikCarVService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 道闸
 *
 * @author jinyiang
 * @date 2023-03-30 14:09:05
 */
@Service
public class CarBarrierServiceImpl extends ServiceImpl<CarBarrierMapper, CarBarrier> implements CarBarrierService {

	@Resource
	private HikCarVService hikCarVService;

	@Override
	public R controller(String barrierNo, Integer num) {

		//掉接口开关
		if (HikFaceUrl.SWITCH.equals("Y")){
			CarDeviceControlRequestDto carDeviceControlRequestDto = new CarDeviceControlRequestDto();
			carDeviceControlRequestDto.setRoadwaySyscode(barrierNo);
			carDeviceControlRequestDto.setCommand(num);
			try {
				CarDeviceControlResultVo carDeviceControlResultVo = hikCarVService.deviceControl(carDeviceControlRequestDto);

				if (carDeviceControlResultVo!=null&&"0".equals(carDeviceControlResultVo.getCode())){
					return R.ok();
				}else{
					return R.failed("接口调用失败"+(StringUtils.isNotEmpty(carDeviceControlResultVo.getMsg())?carDeviceControlResultVo.getMsg():""));
				}

			} catch (Exception e) {
				e.printStackTrace();
				return R.failed("接口调用异常"+e.getMessage());
			}

		}
		return R.ok();
	}
}
